{
  LW Envel -- LightWave Animation Envelopes and Channel Info

  Based on lwenvel.h which is:
  Copyright 1999, NewTek, Inc.
}

{
  Copyright 2012, Jameel Halabi

  This unit is part of the BlaiseWave wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit LW_Envel;

{$mode objfpc}{$H+}

interface

uses
  LW_IO   ,
  LW_Types;

const
  // LWKeyTag
  LWKEY_VALUE      = 0;
  LWKEY_TIME       = 1;
  LWKEY_SHAPE      = 2;
  LWKEY_TENSION    = 3;
  LWKEY_CONTINUITY = 4;
  LWKEY_BIAS       = 5;
  LWKEY_PARAM_0    = 6;
  LWKEY_PARAM_1    = 7;
  LWKEY_PARAM_2    = 8;
  LWKEY_PARAM_3    = 9;

  // Envelope Type
  LWET_FLOAT    = 2;
  LWET_DISTANCE = 3;
  LWET_PERCENT  = 4;
  LWET_ANGLE    = 5;

  // LWEnvTag
  LWENVTAG_VISIBLE    = 0;
  LWENVTAG_PREBEHAVE  = 1;
  LWENVTAG_POSTBEHAVE = 2;
  LWENVTAG_KEYCOUNT   = 3;

  // LWEnvEvent
  LWEEVNT_DESTROY    = 0;
  LWEEVNT_KEY_INSERT = 1;
  LWEEVNT_KEY_DELETE = 2;
  LWEEVNT_KEY_VALUE  = 3;
  LWEEVNT_KEY_TIME   = 4;
  LWCEVNT_VALUE      = 5; // Any change to channel, from channel event only
  LWCEVNT_TRACK      = 6;
  LWCEVNT_CREATE     = 7;
  LWCEVNT_EDITTEST   = 8;
  LWEEVNT_RENAME     = 9; // group has been renamed

  LWENVELOPEFUNCS_GLOBAL = 'Animation Envelopes';
  LWCHANNELINFO_GLOBAL   = 'Channel Info 2';

type
  PLWEnvelope    = Pointer;
  PLWChanGroup   = Pointer;
  PLWEnvKeyframe = Pointer;

  TLWEnvEvent     = Integer;
  TLWEnvEventFunc = function
                    (Data      : Pointer    ;
                     Env       : PLWEnvelope;
                     Event     : TLWEnvEvent;
                     EventData : Pointer    ) : Integer;

  {
    The existing EnvAccess API supported multi-valued keyframes.
    These no longer exist.

    The previous syetem also left the number of channels indeterminate
    until the UI was called, and exposed structures without accepting
    independently created instances of these.

    The replacement global is "Animation Envelopes". Multiple channels
    will be organized into groups, and plugins can logically gather
    their parameters.
  }
  TLWKeyTag = Integer;
  PLWEnvelopeFuncs = ^TLWEnvelopeFuncs;
  TLWEnvelopeFuncs = record
    Create       : function
                   (      Group   : PLWChanGroup   ;
                    const Name    : PChar          ;
                          Type_   : Integer        ) : PLWEnvelope   ;
    Destroy      : procedure
                   (      Env     : PLWEnvelope    ) ;
    CreateGroup  : function
                   (      Parent  : PLWChanGroup   ;
                    const Name    : PChar          ) : PLWChanGroup  ;
    DestroyGroup : procedure
                   (      Group   : PLWChanGroup   ) ;
    Copy         : function
                   (      To_     : PLWEnvelope    ;
                          From    : PLWEnvelope    ) : pLWError      ;
    Load         : function
                   (      Env     : PLWEnvelope    ;
                    const Load    : PLWLoadState   ) : pLWError      ;
    Save         : function
                   (      Env     : PLWEnvelope    ;
                    const Save    : PLWSaveState   ) : pLWError      ;
    Evaluate     : function
                   (      Env     : PLWEnvelope    ;
                          AtTime  : TLWTime        ) : Double        ;
    Edit         : function
                   (      Group   : PLWChanGroup   ;
                          Env     : PLWEnvelope    ;
                          Flags   : Integer        ;
                          Data    : Pointer        ) : Integer       ;
    EnvAge       : function
                   (      Env     : PLWEnvelope    ) : Integer       ;
    CreateKey    : function
                   (      Env     : PLWEnvelope    ;
                          KeyTime : TLWTime        ;
                          Value   : Double         ) : PLWEnvKeyframe;
    DestroyKey   : procedure
                   (      Env     : PLWEnvelope    ;
                          Key     : PLWEnvKeyframe ) ;
    FindKey      : function
                   (      Env     : PLWEnvelope    ;
                          KeyTime : TLWTime        ) : PLWEnvKeyframe;
    NextKey      : function
                   (      Env     : PLWEnvelope    ;
                          Key     : PLWEnvKeyframe ) : PLWEnvKeyframe;
    PrevKey      : function
                   (      Env     : PLWEnvelope    ;
                          Key     : PLWEnvKeyframe ) : PLWEnvKeyframe;
    KeySet       : function
                   (      Env     : PLWEnvelope    ;
                          Key     : PLWEnvKeyframe ;
                          Tag     : TLWKeyTag      ;
                          Value   : Pointer        ) : Integer       ;
    KeyGet       : function
                   (      Env     : PLWEnvelope    ;
                          Key     : PLWEnvKeyframe ;
                          Tag     : TLWKeyTag      ;
                          Value   : Pointer        ) : Integer       ;
    SetEnvEvent  : function
                   (      Env     : PLWEnvelope    ;
                          Ev      : TLWEnvEventFunc;
                          Data    : Pointer        ) : Integer       ;
    EGSet        : function
                   (      Env     : PLWEnvelope    ;
                          Group   : PLWChanGroup   ;
                          Tag     : Integer        ;
                          Value   : Pointer        ) : Integer       ;
    EGGet        : function
                   (      Env     : PLWEnvelope    ;
                          Group   : PLWChanGroup   ;
                          Tag     : Integer        ;
                          Value   : Pointer        ) : Integer       ;
  end;

  {
    The entire list of grouped envelopes can be accessed with the
    "Channel Info" global. These envelopes may include plugin effects,
    and are thus called channels, to distinguish them from the LWEnvelope
    structures, which can be altered through keyframe manipulations. A
    channel's underlying envelope data may also be read.
  }
  TLWChanEventFunc = function
                     (Data      : Pointer   ;
                      Ch        : PLWChannel;
                      Event     : Integer   ;
                      EventData : Pointer   ) : Integer;

  PLWChannelInfo = ^TLWChannelInfo;
  TLWChannelInfo = record
    // next group, first on NULL in parent group or root on NULL
    NextGroup       : function
                      (      Parent   : PLWChanGroup    ;
                             Group    : PLWChanGroup    ) : PLWChanGroup;

    // next channel, first on NULL in parent group or root on NULL
    NextChannel     : function
                      (      Parent   : PLWChanGroup    ;
                             Chan     : PLWChannel      ) : PLWChannel  ;
    GroupName       : function
                      (      Group    : PLWChanGroup    ) : PChar       ;
    ChannelName     : function
                      (      Chan     : PLWChannel      ) : PChar       ;
    GroupParent     : function
                      (      Group    : PLWChanGroup    ) : PLWChanGroup;
    ChannelParent   : function
                      (      Chan     : PLWChannel      ) : PLWChanGroup;
    ChannelType     : function
                      (      Chan     : PLWChannel      ) : Integer     ;
    ChannelEvaluate : function
                      (      Chan     : PLWChannel      ;
                             ChanTime : TLWTime         ) : Double      ;
    ChannelEnvelope : function
                      (      Chan     : PLWChannel      ) : PLWEnvelope ;
    SetChannelEvent : function
                      (      Chan     : PLWChannel      ;
                             Ev       : TLWChanEventFunc;
                             Data     : Pointer         ) : Integer     ;
    Server          : function
                      (      Chan     : PLWChannel      ;
                       const Cls      : PChar           ;
                             Idx      : Integer         ) : PChar       ;

    // Version 2 additions, all index arg.s are 1-based, matching layout
    ServerFlags     : function
                      (      Chan     : PLWChannel      ;
                       const Cls      : PChar           ;
                             Idx      : Integer         ) : UInt32      ;
    ServerInstance  : function
                      (      Chan     : PLWChannel      ;
                       const Cls      : PChar           ;
                             Idx      : Integer         ) : PLWInstance ;

    //  Return 1-based index, or 0 on failure
    ServerApply     : function
                      (      Chan     : PLWChannel      ;
                       const Cls      : PChar           ;
                       const Name     : PChar           ;
                             Flags    : Integer         ) : Integer     ;
    ServerRemove    : procedure
                      (      Chan     : PLWChannel      ;
                       const Cls      : PChar           ;
                       const Name     : PChar           ;
                             Inst     : PLWInstance     ) ;
  end;


implementation

end.

